<?php require_once(dirname(__FILE__) . '/../include/config.inc.php');
require_once "function.php";
/*
进度：
0 已经撤单
1 报修成功
2 客服已经联系
3 系统已经派单
4 工程师接单
5 维修完成
6 已经评价
*/

if (isset($uid)) {

    //有session 从数据库中读取用户名信息
    //$openid_str=$_SESSION['openid'];
    $sql = "SELECT u.*,g.groupname  as groupname FROM `#@__user` as u 
				   left join `#@__usergroup` as g  on u.level=g.id  
				   WHERE u.id='$uid' ";
    $row = $dosql->GetOne($sql);
    if (is_array($row) && isset($row['id'])) {
        // 返回用户 id
        $id = $row['id'];
        $_SESSION['id'] = $id;
        $userInfo = $row;
        $level = intval($row['level']);
    }
}


/*
1、管理员
2、商务
3、工程师
4、用户


*/

if ($level < 5) {
// 我的任务
    $dosql->Execute("SELECT `id` FROM `#@__order` WHERE `jindu`=6  AND  FIND_IN_SET('$uid',manageid)   AND  is_delete=0   ", 12);
    $my_count2 = $dosql->GetTotalRow(12); //已评价

    $dosql->Execute("SELECT `id` FROM `#@__order` WHERE `jindu`=3   AND  FIND_IN_SET('$uid',manageid)  and  is_delete=0    ", 14);
    $my_count4 = $dosql->GetTotalRow(14); //维修中

    $dosql->Execute("SELECT `id` FROM `#@__order` WHERE `jindu`=4  AND  FIND_IN_SET('$uid',manageid)  and  is_delete=0    ", 15);
    $my_count5 = $dosql->GetTotalRow(15); //报修完成

    $dosql->Execute("SELECT `id` FROM `#@__order` WHERE `jindu`=5  AND  FIND_IN_SET('$uid',manageid)   and is_delete=0    ", 16);
    $my_count6 = $dosql->GetTotalRow(16); //报修完成

}
?>
    <!DOCTYPE html>
    <html>
    <head>
        <title>项目经理管理-<?php echo $cfg_webname; ?></title>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="description" content="<?php echo $cfg_webname; ?>">
        <link rel="stylesheet" href="lib/weui.min.css">
        <link rel="stylesheet" href="css/jquery-weui.css">
        <link rel="stylesheet" href="css/font-awesome.min.css">
        <link rel="stylesheet" href="css/demos.css">
        <link rel="stylesheet" href="/admin/ui/css/bootstrap.min.css">
        <link rel="stylesheet" href="/admin/ui/css/bootstrap-theme.min.css">

    </head>

<body>
<style>
    .weui-panel {
        margin: 0;
    }

    .weui-media-box {
        padding: 8px 15px;
    }

    .weui-panel__bd .weui-media-box__hd {
        width: 50px;
        height: 50px;
        line-height: 50px;
        position: relative;
    }

    .weui-media-box__desc {
        -webkit-line-clamp: 1;
    }

    .weui-media-box__title {
        margin-top: -4px;
    }

    .label {
        display: inline;
        padding: 2px 5px;
        font-size: 12px;
        font-weight: 700;
        line-height: 1;
        color: #fff;
        text-align: center;
        white-space: nowrap;
        vertical-align: baseline;
        border-radius: 5px;
        margin-right: 8px;
    }
</style>
<div class="top">
    <div class="user_top">
        <i>
            <?php
            if (intval($row['level']) > 1) {
                echo '<a href="manage.php">' . $userInfo['groupname'] . '</a>';
            } else {
                echo $userInfo['groupname'];
            } ?>
            UID:<?php echo $id; ?>
        </i>
        <div class="user_top_conn"><img src="<?php echo $userInfo['headimgurl'] ?>"/>
            <p><?php echo $userInfo['truename'] ?></p>
            <?php if (intval($row['level']) < 5) { ?><a class="user_link" href="member.php">返回用户</a><?php } ?>
        </div>
    </div>
</div>


<!-- 报修信息 -->
<div class="main">
    <div class="weui-cells__title"><i class="fa fa-id-card-o" aria-hidden="true"></i>工程师列表</div>
    <div class="weui-panel weui-panel_access">
        <div class="weui-panel__bd">
            <!--工单列表开始-->
            <?php
            $sql = "SELECT * FROM `#@__user` WHERE   `level`<5     ORDER BY id asc";
            $dopage->GetPage($sql, 10);
            while ($row = $dosql->GetArray()) {

                $str = "";
                if ($row['ispm'] == 1) {
                    $str .= '<span class="label label-danger">项目经理</span>';
                }
                if ($row['qiang'] == 1) {
                    $str .= '<span class="label label-success">可抢单</span>';
                }
                if ($row['isadmin'] == 1) {
                    $str .= '<span class="label label-info">管理员</span>';
                }

                echo '<div class="weui-media-box weui-media-box_appmsg">
                <div class="weui-media-box__hd">
                    <img class="weui-media-box__thumb" src="' . $row['headimgurl'] . '" alt="">
                   
                </div>
                <div class="weui-media-box__bd">
                    <h4 class="weui-media-box__title">
                        ' . $row['truename'] . '
                        <span class="weui-media-box__title-after">' . $row['mobile'] . '</span>
                    </h4>
                    <p class="weui-media-box__desc">' . $str . '</p>
                </div>
                <div class="weui-media-box__hd">
                    <button type="button" class="btn btn-success btn-sm" onclick="setting(' . $row['id'] . ')">设置</button>
                </div>
            </div>';

            } ?>
        </div>
    </div>
    <!--工单列表结束-->
    <div class="page-div">

        <?php echo $dopage->GetList(); ?>

    </div>
</div>

<div class="clear"></div>
<div class="sub_btn"></div>


<!-- 其他信息 /-->
</div>
<div class="clear"></div>
<script src="lib/jquery-2.1.4.js"></script>
<script src="lib/fastclick.js"></script>
<script src="js/layer/layer.js"></script>
<script>
    $(function () {
        FastClick.attach(document.body);


    });


    function setting(id) {
        console.log(id);
        $.ajax({
            url: "pm_do.php",
            dataType: 'json',
            type: "post",
            data: {
                'op': 'getUser',
                'id': id
            },
            error: function () {
                console.log("提交失败");
            },
            success: function (res) {

                if (res.data.qiang == 0) {
                    str0 = "  checked  ";
                    str1 = "    ";
                }
                if (res.data.qiang == 1) {
                    str0 = "    ";
                    str1 = "  checked  ";
                }
                if (res.data.ispm == 0) {
                    pm0 = "  checked  ";
                    pm1 = "    ";
                }
                if (res.data.ispm == 1) {
                    pm0 = "    ";
                    pm1 = "  checked  ";
                }

                layer.open({
                    type: 1,
                    title: false,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['300px', '400px'], //宽高
                    content: '<div  class="alert-mobile-box no-auth-code">\n' +
                        '                    <span class="ajax-error hide"></span>\n' +
                        '                    <div class="desc text-center"><h4>工程师管理</h4><br><span style="color:darkred">' + res.data.truename + '    ' + res.data.mobile + '</span></div>\n' +
                        '<div class="desc">抢单权限：<label class="radio-inline">\n' +
                        '  <input type="radio" name="qiang" id="" value="1" ' + str1 + ' > 是\n' +
                        '</label>\n' +
                        '<label class="radio-inline">\n' +
                        '  <input type="radio" name="qiang" id="" value="0" ' + str0 + '> 否\n' +
                        '</label></div>' +
                        '<div class="desc">项目经理：<label class="radio-inline">\n' +
                        '  <input type="radio" name="ispm" id="" value="1" ' + pm1 + ' > 是\n' +
                        '</label>\n' +
                        '<label class="radio-inline">\n' +
                        '  <input type="radio" name="ispm" id="" value="0" ' + pm0 + '> 否\n' +
                        '</label></div>' +

                        '<div class="error-tip"></div>\n' +
                        '<span class="btn-submit" onclick="setting_do(' + id + ')">提交</span>\n' +
                        '<div class="protocal">\n' +

                        '</div>\n' +
                        '<i class="close"><i>\n' +
                        '</i></i></div>'
                });
            }
        })

    }

    function setting_do(id) {
        var qiang = $("input[name='qiang']:checked").val();
        var ispm = $("input[name='ispm']:checked").val();
        if (id !== "") {
            $.ajax({
                type: 'POST',
                url: "pm_do.php",
                data: {
                    id: id,
                    op: 'update',
                    'pmid': id,
                    'qiang': qiang,
                    'ispm': ispm,
                },
                dataType: 'JSON',
                success: function (result) {
                    console.log(result);
                    if (result.code == 0) {

                        parent.layer.msg('操作成功', {shade: 0.3});
                        $.toast("设置成功", function () {
                            window.location.href = location.href;
                        });
                    } else {
                        $.alert(result.msg);
                    }
                }
            });
        } else {
            $.alert("请重试", "温馨提示");
        }
    }

</script>
<script src="js/jquery-weui.js"></script>

<script>

</script>
<div class="sub_btn"></div>
<?php require_once('footer.php'); ?>